import { Context, Next } from 'koa'
import { IPagingQueryParams } from '@/types/index.type'
import {
  PARAMS_IS_REQUIRED
} from '@/constants/error-types'

export const verifyPagingSearch = async (ctx: Context, next: Next) => {
  const { pageNum, pageSize } = ctx.request.query as unknown as IPagingQueryParams
  if (Number(pageNum) < 0 && Number(pageSize) < 0) {
    const error = new Error(PARAMS_IS_REQUIRED)
    return ctx.app.emit('error', ctx, error)
  }
  await next()
}